package com.yungu.swift.common.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminPageParam;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.common.dao.CommonFeedbackMapper;
import com.yungu.swift.common.model.dto.CommonFeedbackDto;
import com.yungu.swift.common.model.dto.FeedbackItemDto;
import com.yungu.swift.common.service.CommonFeedbackService;
import com.yungu.swift.utils.MapUtils;
import com.yungu.swift.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * Copyright © 厦门云谷互联信息科技有限公司 2018-2020 All Right Reserved
 * <p>
 * 反馈业务逻辑接口实现类
 *
 * @author Zerrion
 * @version 1.1.0-SNAPSHOT
 * @since 2018-07-05 11:28
 */
@Service
public class CommonFeedbackServiceImpl extends BaseServiceImpl<CommonFeedbackDto> implements CommonFeedbackService {
    @Autowired
    private CommonFeedbackMapper commonFeedbackMapper;

    @Override
    protected IMapper<CommonFeedbackDto> getMapper() {
        return commonFeedbackMapper;
    }


    @Override
    public <PageParam extends AdminPageParam> ResponseData<PageVo<CommonFeedbackDto>> queryPage(PageParam pageParam) {
        PageBounds pageBounds = new PageBounds(pageParam.getPageNum(), pageParam.getPageSize());
        Map<String, Object> beanMap = MapUtils.convertObjToMap(pageParam);
        beanMap.remove("userUuid");
        PageList<CommonFeedbackDto> pageList = this.getMapper().queryPage(beanMap, pageBounds);
        PageVo<CommonFeedbackDto> pageVo = new PageVo(pageParam.getPageNum(), pageParam.getPageSize(), pageList.getPaginator().getTotalCount());
        pageVo.setItems(pageList);
        return ResponseData.buildSuccessResponse(pageVo);
    }

    @Override
    public ResponseData<List<CommonFeedbackDto>> list(Map<String, Object> paramMap) {
        paramMap.remove("userUuid");
        return super.list(paramMap);
    }

    @Override
    public ResponseData<Boolean> feedback(String userUuid, Integer clientSide, String content) {
        CommonFeedbackDto commonFeedbackDto = new CommonFeedbackDto();
        commonFeedbackDto.setUuid(StringUtils.buildUUID());
        commonFeedbackDto.setUserUuid(userUuid);
        commonFeedbackDto.setIdentity(clientSide);
        commonFeedbackDto.setContent(content);
        commonFeedbackDto.setCreateOn(new Date());
        commonFeedbackDto.setStatus(CommonFeedbackDto.STATUS_UNREPLY);
        return add(commonFeedbackDto);
    }

    @Override
    public ResponseData<List<FeedbackItemDto>> listFeedback(String userUuid) {
        return ResponseData.buildSuccessResponse("获取反馈列表成功", commonFeedbackMapper.listFeedback(userUuid));
    }
}